'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('minaTask', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        minaDriverName: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        minaDriverPhone: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        progress: {
            type: Sequelize.JSON,
        },
        rejectMsg: {
            type: Sequelize.JSON,
        },
        status: {
            type: Sequelize.INTEGER(8),
            defaultValue: 0,
            allowNull: false,
        },
        review: {
            type: Sequelize.STRING(150),
        },
        reviewImages: {
            type: Sequelize.JSON,
        },
        score: {
            type: Sequelize.INTEGER(3),
        },
        vehicleLiceUrl: {
            type: Sequelize.STRING,
        },
        insuranceUrl: {
            type: Sequelize.STRING,
        },
        frontUrl: {
            type: Sequelize.STRING,
        },
        dashboardUrl: {
            type: Sequelize.STRING,
        },
        receiptUrl: {
            type: Sequelize.STRING,
        },
        pictures: {
            type: Sequelize.JSON,
        },
        arrivalAt: {
            type: Sequelize.DATE,
        },
        completeAt: {
            type: Sequelize.DATE,
        },
    }, {
        freezeTableName: true,
        tableName: 'mina_task',
        timestamps: true,
        paranoid: true,
    })

    Model.associate = function() {
        model.MinaTask.belongsTo(model.MinaOrder)
        model.MinaTask.belongsTo(model.MinaDriver)
        model.MinaOrder.hasMany(model.MinaTask)
        model.MinaDriver.hasMany(model.MinaTask)
    }

    return Model
}